export default {
    // 当前播放歌曲
    setCurrentSong(state, song) {
        state.currentSong = song
    },
    // 当前播放时长
    setCurrentTime(state, time) {
        state.currentTime = time
    },
    // 播放状态
    setPlayingState(state, playing) {
        state.playing = playing
    },
    // 播放模式
    setPlayMode(state, mode) {
        state.playMode = mode
    },
    // 播放列表显示
    setPlaylistShow(state, show) {
        state.isPlaylistShow = show
    },
    // 播放提示显示
    setPlayerShow(state, show) {
        state.isPlayerShow = show
    },
    // 歌曲详情页显示
    setPlaylistPromptShow(state, show) {
        state.isPlaylistPromptShow = show
    },
    // 播放列表数据
    setPlaylist(state, playlist) {
        const { isPlaylistShow, playlist: oldPlaylist } = state
        state.playlist = playlist
        // 播放列表未显示 并且两次播放列表的不一样 则弹出提示
        if (!isPlaylistShow && !shallowEqual(oldPlaylist, playlist)) {
            state.isPlaylistPromptShow = true
            setTimeout(() => {
                state.isPlaylistPromptShow = false
            }, 2000)
        }
    },
    // 播放历史数据
    setPlayHistory(state, history) {
        state.playHistory = history
    },
    // 菜单显示
    setMenuShow(state, show) {
        state.isMenuShow = show
    },
}

// 比较两个数组是否相等
function shallowEqual(a, b) {
    if (a.length !== b.length) {
        return false
    }
    for (let i = 0; i < a.length; i++) {
        if (!Object.is(a[i], b[i])) {
            return false
        }
    }
    return true
}
